<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
        <script type="text/javascript">
        function getElements()
          {
          var x=document.getElementsByTagName("input");
          //方法可返回带有指定标签名的对象的集合
          alert(x.length);
          }
        </script>
</head>
<body>
    <input name="myInput" type="text" size="20" /><br />
    <input name="myInput" type="text" size="20" /><br />
    <input name="myInput" type="text" size="20" /><br />
    <br />
    <input type="button" onclick="getElements()"
    value="How many input elements?" />
</body>
</html>